<?php
// +----------------------------------------------------------------------
// | B5Yii2CMF V3.0 [快捷通用基础管理开发平台]
// +----------------------------------------------------------------------
// | Author=>冰舞 <357145480@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace api\modules\admin\controllers\system;

use api\modules\admin\AuthController;
use api\utils\libs\CommonAction;
use api\utils\libs\TraitToken;
use common\models\system\LoginLog;

class LoginLogController extends AuthController
{
    use CommonAction;
    use TraitToken;

    protected string $model = LoginLog::class;
    protected bool $validate = true;
    protected array $noAction = ['add', 'edit', 'status', 'find'];

    /**
     * 清空
     * @return array
     */
    public function actionClear(): array
    {
        LoginLog::trash();
        return $this->success();
    }

    /**
     * 解锁用户登录token
     */
    public function actionUnlock(): array
    {
        $id = $this->request->post('id', 0);
        if (!$id) return $this->error('参数错误');
        $info = LoginLog::findOne($id);
        if (!$info) return $this->error('登录记录不存在');
        $this->clearTokenByUserName($info->login_name, $info->platform, $info->user_type);
        return $this->success();
    }
}
